package com.awt.moudle;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @authoer zsj
 * @date 2023/4/15 16:02
 */
public class DialogDemo {

    Frame frame = new Frame();

    Button openPatternDialog = new Button("打开模式对话框");

    Button openNotPatternDialog = new Button("打开非模式对话框");

    Dialog patterDialog = new Dialog(frame, "模式对话框", true);
    Dialog notPatterDialog = new Dialog(frame, "非模式对话框", false);

    void init() {
        patterDialog.setBounds(20, 30, 300, 200);
        notPatterDialog.setBounds(20, 30, 300, 200);
        Box main = Box.createVerticalBox();
        main.add(openPatternDialog);
        main.add(openNotPatternDialog);
        frame.add(main);


        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                switch (e.getActionCommand()) {
                    case "打开模式对话框":
                        Box hbox = Box.createHorizontalBox();
                        Box dbox = Box.createVerticalBox();
                        hbox.add(new Button("确定"));
                        hbox.add(new Button("取消"));
                        dbox.add(new TextArea(3,10));
                        dbox.add(hbox,BorderLayout.SOUTH);
                        patterDialog.add(dbox);
                        patterDialog.setVisible(true);
                        notPatterDialog.setVisible(false);
                        break;
                    case "打开非模式对话框":
                        notPatterDialog.add(new Button("点两下？"));
                        notPatterDialog.setVisible(true);
                        patterDialog.setVisible(false);
                        break;
                }
            }
        };

        openPatternDialog.addActionListener(actionListener);
        openNotPatternDialog.addActionListener(actionListener);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new DialogDemo().init();
    }
}
